package com.ease;

public class FourTeen_longestCommonPrefix {
    public static void main(String[] args) {

//       String strs[] = {"flower","flow","flight"};
     String   strs[] =
             {"ab", "a"};
       FourTeen_longestCommonPrefix result=new FourTeen_longestCommonPrefix();
        String s = result.longestCommonPrefix(strs);
        System.out.println(s);
    }

    public String longestCommonPrefix(String[] strs) {
        int length = strs.length;
        String prefix = strs[0];
        if (length == 0) {
            return "";
        }
        for (int i = 1; i < length; i++) {
            int j = 0;
            for (; j < prefix.length() && j < strs[i].length(); j++) {
                if (prefix.charAt(j) != strs[i].charAt(j)) {
                    break;
                }
            }
            prefix = prefix.substring(0, j);
        }
        return prefix;
    }
}
